package com.suhuamo.transtionals.service;

import com.suhuamo.transtionals.mapper.UserMapper;
import com.suhuamo.transtionals.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author yuanchuncheng
 * @slogan yscz
 * @date 2024-10-21
 * @description
 */
@Service
public class BService {
    @Autowired
    private UserMapper userMapper;

    /**
     * 带有事务的方法
     * @param
     * @return void
     * @version 1.0
     * @author yuanchuncheng
     */
    @Transactional
    public void haveTransactional() {
        User user = userMapper.selectById(UserService.id);
        user.addCount();
        userMapper.updateById(user);
        throw new RuntimeException();
        /// ... 后续逻辑
    }

    /**
     * 不带事务的方法
     * @param
     * @return void
     * @version 1.0
     * @author yuanchuncheng
     */
    public void noTransactional() {
        User user = userMapper.selectById(UserService.id);
        user.addCount();
        userMapper.updateById(user);
        throw new RuntimeException();
        /// ... 后续逻辑
    }
}
